package org.artifact.protocol.convert;

import org.artifact.protocol.ProtocolType;

import cn.hutool.core.util.StrUtil;

public abstract class AbstractConvert {
	public ProtocolType convert(String classPath,String type) {
		ProtocolType unit = new ProtocolType();
		unit.setType(doConvert(classPath,StrUtil.subBefore(type, "<", false),true));
		
		// 处理泛型
		if (StrUtil.containsAny(type, "<","|",">")) {
			String generic = StrUtil.subBetween(type, "<", ">");
			String[] generics = StrUtil.split(generic, "|");
			unit.setGenerics(new String[generics.length]);
			for (int i = 0; i < generics.length; i++) {
				unit.getGenerics()[i] = doConvert(classPath,generics[i], false);
			}
		}
		return unit;
	}
	
	protected abstract String doConvert(String classPath,String protocolType,boolean baseType);
}
